import huck
import huck.ext.keyvalue_memcache
import memcache

class MainPage(huck.RequestHandler):
  def get(self):
    count = self.keyvalue.get('count')
    if not count:
      count = 0

    self.response.out.write('<html><body>')
    self.response.out.write('Count: %s' % count)
    self.response.out.write('</body></html>')

    self.keyvalue.set('count', count + 1)

# Setup application
url_mapping = [('/', MainPage),]
application = huck.Application(url_mapping, debug=True)

# Setup resources
huck.api.resource['memcache'] = memcache.Client(['example:11211'], debug=0)

# Setup keyvalue
keyvalue = huck.ext.keyvalue_memcache.Create(resource='memcache')
application = keyvalue.setup(application)

if __name__ == '__main__':
  huck.run_dev('', 8080, application)
